package com.cy.cykh.app.view.base
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.trello.rxlifecycle2.components.support.RxFragment

/**
 * <pre>
 * author : jinliangshan
 * e-mail : jinliangshan@chexiang.com
 * desc   :
</pre> *
 */
abstract class BaseFragment : RxFragment() {

   private var rootView:View? = null
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
            if (rootView == null) {
                rootView = inflater.inflate(getContentViewID(), container, false)
        }
        return rootView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()

    }


    /**
     * 布局
     *
     * @return
     */
    protected abstract fun getContentViewID(): Int

    /**
     * 布局
     *
     * @return
     */
    protected abstract fun initView()

    /**
     * 跳转Activity
     *
     * @param clazz
     */
    protected fun GoActivity(clazz: Class<*>) {
        val intent = Intent(activity, clazz)
        startActivity(intent)
        //getActivity().overridePendingTransition(R.anim.trans_next_in, R.anim.trans_next_out);
    }

    /**
     * 跳转Activity bundle
     *
     * @param clazz
     * @param bundle
     */
    protected fun GoActivity(clazz: Class<*>, bundle: Bundle?) {
        val intent = Intent(activity, clazz)
        if (null != bundle) {
            intent.putExtras(bundle)

        }
        startActivity(intent)
    }

    /**
     * 请求码跳转Activity
     *
     * @param clazz
     * @param requestCode
     */
    protected fun GoActivityResult(clazz: Class<*>, requestCode: Int) {
        val intent = Intent(activity, clazz)
        startActivityForResult(intent, requestCode)
    }

    /**
     * 请求码跳转Activity  bundle
     *
     * @param clazz
     * @param requestCode
     * @param bundle
     */
    protected fun GoActivityResult(clazz: Class<*>, requestCode: Int, bundle: Bundle?) {
        val intent = Intent(activity, clazz)
        if (null != bundle) {
            intent.putExtras(bundle)
        }
        startActivityForResult(intent, requestCode)
    }



}
